package mapred.config;

import mapred.task.AbstractMapper;
import mapred.task.extention.DirectMapper;

import org.apache.hadoop.io.Writable;

@SuppressWarnings("unchecked")
public class MapConfig {

    private Class<? extends AbstractMapper> mapperClass;

    private Class<? extends Writable> outputKeyClass;

    private Class<? extends Writable> outputValueClass;

    private int numMapTasks;

    private MapConfig(
            Class<? extends AbstractMapper> mapperClass,
            int numMapTasks, Class<? extends Writable> outputKeyClass,
            Class<? extends Writable> outputValueClass) {
        if (mapperClass == null) {
            this.mapperClass = DirectMapper.class;
        } else {
            this.mapperClass = mapperClass;
        }
        this.numMapTasks = numMapTasks;
        this.outputKeyClass = outputKeyClass;
        this.outputValueClass = outputValueClass;
    }

    public static MapConfig newInstance(
            Class<? extends AbstractMapper> mapperClass,
            int numMapTasks, Class<? extends Writable> outputKeyClass,
            Class<? extends Writable> outputValueClass) {
        return new MapConfig(mapperClass, numMapTasks, outputKeyClass,
                outputValueClass);
    }

    public Class<? extends AbstractMapper> getMapperClass() {
        return mapperClass;
    }

    public Class<? extends Writable> getOutputKeyClass() {
        return outputKeyClass;
    }

    public Class<? extends Writable> getOutputValueClass() {
        return outputValueClass;
    }

    public int getNumMapTasks() {
        return numMapTasks;
    }

}
